/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-11-01
 * Time: 23:08
 */
public class TestH11 {
    public static int hIndex(int[] citations) {
        int len = citations.length;
        int left = 0, right = len;

        while(left < right) {
            int mid = (left+right+1)/2;
            int count = 0;
            for(int c : citations) {
                if(c >= mid) {
                    count++;
                }
            }
            if(count >= mid) {
                left = mid;
            }else {
                right = mid-1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] c = {1,2,3,7,4,5};
        int ret = hIndex(c);
        System.out.println(ret);
    }
}
